# coding=utf-8

import urllib
import requests
import time

# 判断urls中的各个网页里的url是否报错或者404页面，返回错误提示str(error)
# n是暂停多少时间
def get_url_codes(url, n=2):
    error = str()
    url_code = urllib.urlopen(url).code
    if url_code == 200 or url_code == 403:
        new_url = requests.get(url).url
        if "/404.html" in new_url:
            error_404 = url + u" 是404页面！"    # 传入到表的错误字段
            return error_404
        else:
            pass
    else:
        error_code = url + " code is " + str(url_code)    # 传入到表的错误字段
        return error_code
    # time.sleep(n)

# 获取错误的提示或者正确的url
# print get_url_codes(['http://gold.hexun.com/hjxh/'])[0]